\documentclass[10pt,professionalfonts,serif,usenames,dvipsnames,svgnames,table]{beamer}

\include{preamble}
\usepackage[scaled=0.85]{beramono}
\include{phys_defs}

\title{rootpy: Pythonic ROOT}
\subtitle{\href{http://rootpy.org}{rootpy.org}\vspace{-.5cm}}
\author[Noel Dawe]{Noel Dawe}
\date[\today]{\today}
\institute[rootpy]{on behalf of all rootpy contributors}
\titlegraphic{\includegraphics[height=3cm]{../common/images/rootpy_logo.png}}

\begin{document}

\frame{\titlepage
    %\begin{center}
    %{\bf ROOT Users Workshop, Saas-Fee}
    %\end{center}
}

\frame{
    \frametitle{What's the problem?}

    \begin{center}
    {\bf Why would we even consider developing a layer on top of PyROOT?}
    \end{center}

    \begin{itemize}
        \itemsep=.4cm
        \item PyROOT is mainly bindings (although with some pythonization).
        \item Python's dynamic nature provides {\bf many possibilities not
            currently realized by PyROOT}. One might argue a majority of these
            high-level pythonizations are {\bf beyond the scope of what PyROOT should
            offer.}
        \item Certain tasks require awkward code and are error-prone.
            Similar workarounds are implemented by many people in multiple places.\\
            {\bf\em Why not solve these issues once and for all?}
        \item There is a lack of integration of ROOT with the vast and growing
            ecosystem of scientific Python packages.\\ {\bf\em Why not enable users to
            benefit from both the power of ROOT and what is offered by the
            scientific Python community?}
    \end{itemize}
}

\frame{
    \frametitle{Scientific Python Applications}
    \begin{center}
    ``Can I really perform complicated analysis with Python?''\\
    {\bf Short answer: Yup!}
    \end{center}
    \begin{itemize}
        \item \href{http://root.cern.ch/drupal/}{ROOT} with \href{http://root.cern.ch/drupal/content/pyroot}{PyROOT}
        \item Interactive computing: \href{http://jupyter.org/}{Jupyter Notebook}
        \item Powerful and fast array manipulation: \href{http://numpy.scipy.org/}{numpy}
        \item Feature-rich publication-quality plotting: \href{http://matplotlib.org/}{matplotlib}
        \item Efficiently and easily handle large amounts of data: \href{http://www.pytables.org/moin}{PyTables}, \href{http://www.h5py.org/}{h5py}
        \item General scientific library: \href{http://www.scipy.org/}{scipy}
        \item Flexible data analysis and manipulation: \href{http://pandas.pydata.org/}{pandas}
        \item Symbolic mathematics: \href{http://sympy.org/}{sympy}
        \item Statistical models and tests: \href{http://statsmodels.sourceforge.net/}{statsmodels}
        \item Fitting: \href{https://iminuit.readthedocs.io}{iminuit} and \href{https://github.com/sherpa/sherpa}{sherpa}
        \item Astronomy: \href{http://www.astropy.org/}{astropy}
        \item Image processing: \href{http://scikit-image.org/}{scikit-image}
        \item Machine learning: \href{http://scikit-learn.org/stable/}{scikit-learn}
    \end{itemize}
    \begin{center}
        Search for packages on the \href{https://pypi.python.org/pypi}{Python Package Index}
    \end{center}
}

\frame{
    \frametitle{Introducing rootpy\ldots}

    \begin{itemize}
        \item rootpy aims to provide a \textbf{\emph{ more pythonic layer}} on
            top of the PyROOT bindings and to take advantage of advanced
            features of the Python language.
        \item {\bf rootpy does not intend to recreate ROOT} or to {\em severely}
            alter the default behaviour of ROOT.
        \item {\bf rootpy is not an analysis framework}, but rather a library that
            your analysis code might use.
        \item rootpy provides an {\bf interface with the scientific Python
            packages}:
        \end{itemize}
        \begin{center}
            \includegraphics[width=.6\textwidth]{figs/rootpy-map.png}
    \end{center}
}

\frame{
    \frametitle{Why the name ``rootpy''?}

    \begin{center}
        numpy, scipy, h5py, \ldots \hspace{.5cm} See the pattern?
    
    \vspace{1cm}
    ``rootpy'' is meant to automatically convey the idea ``Like PyROOT, but Pythonic?'' 
    
    \vspace{.5cm}

\begin{exampleblock}{}
{\em ``Pythonic means code that doesn't just get the syntax right but that follows
    the conventions$^*$ of the Python community and uses the language in the way it
    is intended to be used.''} 
  \vskip1mm
  \hspace*\fill{\small--- \href{http://stackoverflow.com/a/25011492/1002176}{on stackoverflow}}
\end{exampleblock}

\vspace{.5cm}
{\small * Capitalization is important. Never ROOTPy, RootPy, etc. \\
See \href{https://www.python.org/dev/peps/pep-0008}{PEP8}}

\end{center}
}

{
\setbeamercolor{background canvas}{bg=black,fg=white}
\usebeamercolor[fg]{background canvas}

\begin{frame}[plain]
    \begin{center}
    \includegraphics[height=\textheight]{figs/rootpy-github.png}
    \end{center}
\end{frame}

\begin{frame}[plain]
    \begin{center}
    \includegraphics[width=\textwidth]{figs/rootpy-stats.png}\\
    
    \vspace{1cm}
    {\bf
    19k lines of code\\
    Over 3800 commits in 535 pull requests\\
    Many users and developers from LHC and non-LHC experiments}
    \end{center}
\end{frame}
}

\frame{
    \frametitle{rootpy: Key Concepts and Design Philosophy}

    \begin{itemize}
        \itemsep=.3cm
        \item Pythonized {\bf classes in rootpy are subclasses of the corresponding
            ROOT classes} with the same (or similar) name, but without the ``T''.\\
        \item ROOT methods may be overridden or new methods created to add
            functionality and objects may be decorated with additional properties.
        \item {\bf Object names and titles are optional}. Unspecified names default to
            UUIDs.
        \item ROOT messages can be routed through Python's logging system
            with {\bf error messages raised as Python exceptions}.
        \item {\bf Python has a garbage collector but C++ does not:} this can lead to
            strange issues. rootpy addresses these problems.
        \item Anywhere Python is typically slow we try to use
            {\bf compiled C extension modules}. Through the
            \href{https://github.com/rootpy/root\_numpy}{root\_numpy}
            package, rootpy provides very fast conversion of ROOT Trees into
            NumPy arrays as well as efficiently filling ROOT histograms with
            NumPy arrays.
        \item {\bf rootpy can be dropped into existing code.}
    \end{itemize}
}

\frame{
    \frametitle{What does rootpy offer?}

    \begin{center}
    \rowcolors[]{1}{blue!20}{blue!10}
    \begin{tabular}{l >{\raggedright\arraybackslash}p{8cm}}
        {\bf rootpy.plotting} & histogram, graphs, canvas, pad, legend, and
            style subclasses with additional pythonizations,
            including a matplotlib interface. \\
        {\bf rootpy.tree} & trees, chains, tree objects, tree models, cuts. \\
        {\bf rootpy.io} & file and directory subclasses, utilities, pickler. \\
        {\bf rootpy.logger} & route ROOT messages through Python's
            logging module. ROOT error messages become Python exceptions. \\
        {\bf rootpy.memory} & utilities for monitoring TObject deletions
            and for keeping objects alive when out of scope in Python. \\
        {\bf rootpy.interactive} & a wait function for preventing Python
            from exiting until all canvases have been closed. \\
        {\bf rootpy.stl} & automatic STL dictionary compilation and caching. \\
        {\bf rootpy.root2hdf5} & conversion of ROOT files into HDF5. \\
        {\bf rootpy.context} & utilities for managing ROOT's global state. \\
        {\bf rootpy.stats} & RooStats, RooFit, HistFactory. \\
        \multicolumn{2}{c}{\ldots and more \ldots} \\
        \multicolumn{2}{c}{See the
            \href{https://github.com/rootpy/root\_numpy}{root\_numpy}
        package for conversion of TTrees into NumPy arrays.}\\
        \end{tabular}
    \end{center}
}

\begin{frame}[fragile]
    \frametitle{Histograms}
    {\bf PyROOT}
    \vspace{-.2cm}
    \include{examples/hist}
    {\bf rootpy}
    \vspace{-.2cm}
    \include{examples/hist_rootpy}
\end{frame}

\begin{frame}[fragile]
    \frametitle{Histograms and Style}
    \begin{itemize}
        \item rootpy reduces ROOT's histogram classes down to Hist, Hist2D,
            Hist3D.
\begin{pyglist}[language=python,style=vs]
>>> from rootpy.plotting import Hist2D
>>> hist = Hist2D(10, 0, 1, 5, 0, 1, type='F')
>>> hist.__class__.__bases__[-1].__name__
'TH2F'
\end{pyglist}
\item Attributes can be accessed via properties:
\begin{pyglist}[language=python,texcl=true,style=vs]
hist.title = 'Fit Result'
hist.fillstyle = 'solid'
\end{pyglist}
\item Colors can also be set using hex, RGB tuples, or SVG names:
\begin{pyglist}[language=python,texcl=true,style=vs]
hist.fillcolor = (32, 178, 170)
hist.linecolor = '#87cefa'
hist.markercolor = 'salmon'
\end{pyglist}
\item Histograms can be indexed and sliced like multidimensional arrays
\begin{pyglist}[language=python,texcl=true,style=vs]
hist[:] = hist.Clone()[::-1]  # reverse bin content and errors
\end{pyglist}
\end{itemize}
\end{frame}

\begin{frame}[fragile]
    \frametitle{Cuts}
    \begin{columns}
        \column[t]{.45\textwidth}
        {\bf PyROOT}
        \include{examples/cuts}
        \vspace{-.3cm}
        output:
        \vspace{-.3cm}
        \include{examples/cuts_output}
        \column[t]{.45\textwidth}
        {\bf rootpy}
        \include{examples/cuts_rootpy}
        \vspace{-.3cm}
        output:
        \vspace{-.3cm}
        \include{examples/cuts_rootpy_output}
    \end{columns}
\end{frame}

\begin{frame}[fragile]
    \frametitle{PyROOT: ``Exception Handling''}

ROOT is unable to open the file of course and emits an error message but an
exception is not raised at this point leading to (sometimes difficult to
interpret) issues downstream:

    \include{examples/file_open}
    \vspace{-.5cm}
    \include{examples/file_open_output}
\end{frame}

\begin{frame}[fragile]
    \frametitle{rootpy: Exception Handling}

rootpy routes ROOT messages through Python's logging system and raises error
messages as Python exceptions at the point of failure:

    \include{examples/file_open_rootpy}
    \vspace{-.5cm}
    \include{examples/file_open_rootpy_output}
    \begin{center}
        \vspace{-.5cm}
    {\bf An exception is raised at the point of failure!}
    \end{center}
\end{frame}

\begin{frame}[fragile]
    \frametitle{rootpy: Files}
    \begin{itemize}
\item Simple dictionary-like access:
\begin{pyglist}[language=python,style=vs]
hist = myfile['histname']
myfile['new_name'] = hist
myfile.dirname.histname = hist
\end{pyglist}
    \item Can be used as context managers:
\begin{pyglist}[language=python,style=vs]
from rootpy.io import TemporaryFile
with TemporaryFile() as f:
    # current directory is f
    pass
# current directory restored to previous state
# and f is closed (and deleted in this case)
\end{pyglist}
    \item Utilities such as walking the contents of a file:   
\begin{pyglist}[language=python,style=vs]
# recursively walk through the file
for path, dirs, objects in f.walk():
    print path, dirs, objects
\end{pyglist}
\end{itemize}
\end{frame}

\begin{frame}[fragile]
    \frametitle{PyROOT: Filling a Tree}
    \include{examples/tree}
\end{frame}

\begin{frame}[fragile]
    \frametitle{rootpy: Filling a Tree}
    \begin{columns}
        \column[t]{.45\textwidth}
        {\bf Create and handle branches automatically:}
        \include{examples/tree_rootpy}
        \column[t]{.45\textwidth}
        {\bf or with ``TreeModels'':}
        \include{examples/tree_rootpy_with_model}
    \end{columns}
\end{frame}

\begin{frame}[fragile]
    \frametitle{rootpy: Tree Models}
    Easily create complex trees by simple class inheritance (inspired by
    PyTables):
    \vspace{-.6cm}
    \begin{columns}
        \column[t]{.45\textwidth}
    \include{examples/tree_model_rootpy}
    \column[t]{.45\textwidth}

    \vspace{.8cm}

    Branches are constructed according to the requested model:
    \include{examples/tree_model_rootpy_output}
    \vspace{-.3cm}
    Support for default values, automatic STL dictionaries, ROOT objects.
    \end{columns}
\end{frame}

\begin{frame}[fragile]
    \frametitle{Object Ownership and Garbage Collection}
    \begin{columns}
        \column[t]{.45\textwidth}
        {\bf PyROOT}
    \include{examples/memory}
        \column[t]{.45\textwidth}
        {\bf rootpy}
    \include{examples/memory_rootpy}
    Objects are kept alive as long as the Canvas is alive. \\
    {\bf See rootpy's keepalive function.}
    \end{columns}
\end{frame}

\begin{frame}
    \frametitle{rootpy: Interface with matplotlib}
    ROOT histograms
    \href{https://github.com/rootpy/rootpy/blob/master/examples/plotting/plot_matplotlib_hist.py}{
    can be drawn with matplotlib} via rootpy's
    \href{https://github.com/rootpy/rootpy/blob/master/rootpy/plotting/root2matplotlib.py}{
    matplotlib interface}:
    \begin{center}
    \includegraphics[width=.9\textwidth]{figs/examples/matplotlib_example.png}\\
    \href{http://matplotlib.org/gallery.html}{matplotlib}: highly customizable,
    multiple backends, uses your latex engine.
\end{center}
\end{frame}

\begin{frame}[fragile]
    \frametitle{rootpy.ROOT: drop-in ``import ROOT'' replacement}

    \begin{itemize}
    \itemsep=0.3cm
\item Harmonize access to ROOT and rootpy classes and take advantage of rootpy classes automatically.

\item Replace \framebox{\texttt{import ROOT}} with \framebox{\texttt{from rootpy import ROOT}}

\item Maintain backward compatibility with existing use of ROOT's classes.

\item ROOT classes are automatically cast to their rootpy form after the constructor in ROOT has been called:
    \begin{minted}{python}
>>> from rootpy import ROOT
>>> ROOT.TH1F('name', 'title', 10, 0, 1)
Hist('name')
    \end{minted}

\item Also access rootpy classes under this same module without needing to remember where to import them from in rootpy:
    \begin{minted}{python}
>>> ROOT.Hist(10, 0, 1, name='name', type='F')
Hist('name')
    \end{minted}
\end{itemize}

\end{frame}


\frame{
    \frametitle{Future Objectives}

    \begin{itemize}
        \itemsep=0.3cm
        \item Larger documentation coverage and more examples. {\bf This is important!}
        \item Full Python 3 support.
        \item Better integration with Jupyter Notebooks:
            \begin{itemize}
                \item Full tab completion and helpful builtin commands like pylab
                \item Fetch documentation on-demand for a class/method/function
                \item Inline ROOT plots that are interactive
                \end{itemize}
                Great to see progress in \href{https://root.cern.ch/doc/master/md_bindings_pyroot_ROOTaaS_README.html}{ROOTaaS}
                and \href{https://root.cern.ch/js/}{jsROOT}
        \item Automatic wrapping of ROOT methods by parsing method signatures:
            \begin{itemize}
                \item Automatic argument/return value conversion. If a method expects a TColor, rootpy can accept any matplotlib/ROOT color
                      and convert it into a TColor before passing to the ROOT method.
                \item Automatically create descriptors from ROOT get/setters
                \item Reduce the amount of code in rootpy.
                \end{itemize}
        \item rootpy version 1.0 will be the first ``stable'' release where we 
           freeze the API and begin proper deprecation cycles if needed.
           {\bf rootpy is already very close!}
   \end{itemize}
}

\begin{frame}[fragile]
    \frametitle{How do I install rootpy?}
    \begin{center}
        Install a \href{https://pypi.python.org/pypi/rootpy}{released version}
        with \href{https://pypi.python.org/pypi/pip}{pip}:
        \vspace{.5cm}

        \texttt{pip install -{}-user rootpy}
        
        \vspace{.5cm}
See the \href{http://www.rootpy.org/install.html}{documentation} for full instructions.
    \end{center}
\end{frame}

%\begin{frame}[fragile]
    %\frametitle{How can you contribute?}

    %\begin{center}
    %\includegraphics[width=5cm]{figs/we-want-you.jpg}
    %\end{center}

    %\begin{itemize}
        %\item Development is community-driven.
        %\item We use Git! See the rootpy collaboration on GitHub:
            %\href{https://github.com/rootpy}{github.com/rootpy}
        %\item Just fork rootpy into your own GitHub account and:
            %\begin{pyglist}[language=bash,texcl=true,style=vim]
%git clone git@github.com:<username>/rootpy.git
            %\end{pyglist}
              %Then submit a pull request with your contribution.
        %\item Contributions are reviewed by peers before merging into the main branch.
        %\item All new code automatically triggers our test suite using
            %\href{https://travis-ci.org/}{Travis CI}.
    %\end{itemize}
%\end{frame}

%\begin{frame}
    %\begin{large}
    %\begin{center}
    %\begin{columns}
        %\column[t]{.4\textwidth}
%{\bf The Developers:}
%\vspace{.5cm}
%\begin{itemize}
    %\item Noel Dawe
    %\item Peter Waller
    %\item Piti Ongmongkolkul
    %\item Christoph Deil
    %\item Evan Friis
    %\item Jeff Klukas
%\end{itemize}
%\column[t]{.55\textwidth}
%{\bf Where to find us:}
%\vspace{.5cm}
        %\begin{itemize}
            %\item \href{http://rootpy.org}{rootpy.org}
            %\item \href{https://github.com/rootpy}{github.com/rootpy}
            %\item \href{http://www.ohloh.net/p/rootpy}{ohloh.net/p/rootpy}
            %\item rootpy-dev@googlegroups.com
            %\item rootpy-users@googlegroups.com
            %\end{itemize}
        %\end{columns}
    %\end{center}
    %\end{large}
%\end{frame}

\end{document}
